var data1 =  [
    {
        name : "张三",
        age  : 19,
        description : "一只张三"
    },
    {
        name : "张三",
        age  : 19,
        description : "2只张三"
    },
    {
        name : "张三",
        age  : 19,
        description : "3只张三"
    },
    {
        name : "张三",
        age  : 19,
        description : "4只张三"
    },
    {
        name : "张三",
        age  : 19,
        description : "5只张三"
    },
    {
        name : "张三",
        age  : 19,
        description : "6只张三"
    },
    {
        name : "张三",
        age  : 19,
        description : "一只张三"
    },
    {
        name : "张三",
        age  : 19,
        description : "一只张三"
    },
    {
        name : "张三",
        age  : 19,
        description : "一只张三"
    }
]
var dataArr = []
var xls = require("exceljs");
 
const createExcel = (username,password,registerDate) => {
    // 新建一个工作表
    var workbook = new xls.Workbook();
    // 创建日期
    workbook.created = new Date();
    // 修改日期
    workbook.modified = new Date();
    // 作者名称
    workbook.creator = 'bear';
    // 最后修改人
    workbook.lastModifiedBy = 'bear';
 
    // 添加sheet，并且初始化该sheet的名称
    let sheet = workbook.addWorksheet('测试报表');
 
    // 设置表头
    // sheet.columns = [
    //     {header: 'Name', key: 'name', width: 15},
    //     {header: 'Age', key: 'age', width: 15},
    //     {header: 'Description', key: 'description', width: 15}
    // ];

    sheet.columns = [
        {header: '用户名', key: 'username'},
        {header: '密码', key: 'password'},
        {header: '注册时间', key: 'registerDate'}
    ];
    dataArr.push({username:username,password:password,registerDate:new Date()})
    // 添加多行，data1要是个数组类型(能用foreach遍历)  入参dataArr必须是数组
    sheet.addRows(dataArr);
 
    // 写文件
    workbook.xlsx.writeFile('./filename.xlsx')
    .then(function() {
        // done
        console.log('write done')
    });
 
};
 
module.exports = createExcel